public class T {

    public void crreat(){
        n1.next=n2;
        n2.next=n3;
        n3.next=n4;
        n4.next=n5;
        n5.next=n6;
        n6.next=null;
    }

    ListNode n1=new ListNode(1);
    ListNode n2=new ListNode(2);
    ListNode n3=new ListNode(3);
    ListNode n4=new ListNode(3);
    ListNode n5=new ListNode(2);
    ListNode n6=new ListNode(1);

    public static void main(String[] args) {
        T t=new T();
        t.crreat();
        System.out.println(PalindromeList.chkPalindrome(t.n1));


    }
}




 class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
 class PalindromeList {
    static public boolean chkPalindrome(ListNode A) {

        if(A==null){
            return true ;
        }
        // write code here
        ListNode cur=null;
        ListNode fast=A;
        ListNode slow=A;
        ListNode prev=slow;
        ListNode next;

        while (fast!=null&&fast.next!=null){


            fast=fast.next.next;

            slow=slow.next;
        }

        prev=slow;

        next=slow.next;
        slow.next=null;
        cur=slow;

        while(next!=null){

            slow=next;
            next=next.next;

            slow.next=cur;
            cur=slow;

        }



        while (slow!=null&&A!=null){
            if(slow.val!= A.val){
                return false;
            }else {
                slow=slow.next;
                A=A.next;
            }
        }

        if(slow==null&&A==prev){
            return true;
        }else {
            return false;
        }



    }
}